package com.xucy.springboot.activemq;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xucy
 * @Date 2019-07-05 10:11
 * @Description
 **/

@RestController
@RequestMapping("/mqPro")
public class MqProducer {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * 发送字符串队列
     *
     * @Author xucy
     * @Date 10:27 2019-07-05
     * @param
     * @return
     */
    @RequestMapping("/sendQueueString")
    public String sendQueueString(){

        String queueName="myQueue";
        String message="我的queue";
        jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(queueName),message);

        return "成功发送";
    }

    @RequestMapping("/sendQueueList")
    public String sendQueueList(){

        String queueName="myQueueList";
        List<String> stringList=new ArrayList<>();
        stringList.add("xu");
        stringList.add("chen");
        stringList.add("yang");
        jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(queueName),stringList);

        return "成功发送";
    }


    @RequestMapping("/sendQueueObject")
    public String sendQueueObject(){

        String queueName="myQueueObject";
        User user=new User("徐晨阳",18);
        jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(queueName),user);

        return "成功发送";
    }

    @RequestMapping("/sendQueueListObject")
    public String sendQueueListObject(){

        List list=new ArrayList();
        list.add(new User("狮子",18));
        list.add(new User("老虎",19));
        list.add(new User("大象",20));

        String queueName="myQueueObjectList";
        jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(queueName),list);

        return "成功发送";
    }

}
